import pymysql




def test1():
    conn=pymysql.connect(host='127.0.0.1',port=3306,user='root',password='root',db='test1',charset='utf8')
    sql='INSERT INTO test1_1 VALUES(1,2)'
    try:
        with  conn.cursor() as cur:
            result=cur.execute(sql)
            if result==1:
                print('添加成功')
            conn.commit()
    except Exception as e:
        print(e)
        conn.rollback()
    finally:
        conn.close()


def test2():
    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='root', db='test1', charset='utf8')
    sql = 'SELECT * FROM test1_1'

    with  conn.cursor() as cur:
        cur.execute(sql)
        for i in cur.fetchall():
            print(i)
    conn.close()

def test3():
    conn = pymysql.connect(host='127.0.0.1',
                           port=3306,
                           user='root',
                           password='root',
                           db='test1',
                           charset='utf8',
                           cursorclass=pymysql.cursors.DictCursor) #查询的结果为字典类型
    sql = 'SELECT * FROM test1_1 WHERE id=%s'

    with  conn.cursor() as cur:
        cur.execute(sql,(1,))
        for i in cur.fetchall():
            print(i)
    conn.close()
# {'id': 1, 'age': 34}
if __name__ == '__main__':
    str='10'
    a=int(str)
    print(type(a))

    pass
